home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98c.txt / 000126_icon-group-sender _Thu Dec 10 17:11:13 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id RAA07859
  4.     for icon-group-addresses; Thu, 10 Dec 1998 17:10:36 -0700 (MST)
  5. Message-Id: <199812110010.RAA07859@baskerville.CS.Arizona.EDU>
  6. Date: Thu, 10 Dec 1998 12:43:24 -0500 (EST)
  7. From: "R. Clayton" <clayton@cc.gatech.edu>
  8. To: icon-group@optima.CS.Arizona.EDU
  9. Subject:  Plus, also, too.
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13.   I'd just like to say a few words on behalf of our forgotten friends, the
  14.   regular expressions:
  15.  
  16.     ma cat re.icn
  17.     link regexp
  18.  
  19.     procedure main()
  20.  
  21.       local pat, cnt, l
  22.  
  23.       pat := RePat("(XMULT|XZERO|YMULT|YZERO):([0-9]+\.[0-9]*E[-+][0-9]+)")
  24.       cnt := 0
  25.  
  26.       while l := read() do
  27.     every ReFind(pat, l) do {
  28.       write(Re_ParenGroups[1], " is ", Re_ParenGroups[2]) 
  29.       cnt +:= 1
  30.       }
  31.  
  32.       write("cnt = ", cnt)
  33.  
  34.       end # main
  35.  
  36.     ma icont -u re.icn
  37.     Translating:
  38.     re.icn:
  39.       main
  40.     No errors
  41.     Linking:
  42.  
  43.     ma ./re < dat
  44.     XMULT is 1.11E-4
  45.     XMULT is 1.12E-4
  46.     XMULT is 1.13E-4
  47.     XMULT is 1.14E-4
  48.     XZERO is 4.21E-8
  49.     XZERO is 4.22E-8
  50.     XZERO is 4.23E-8
  51.     YMULT is 1.31E-6
  52.     YMULT is 1.32E-6
  53.     YMULT is 1.33E-6
  54.     YZERO is 0.41E+0
  55.     YZERO is 0.42E+0
  56.     YZERO is 0.43E+0
  57.     cnt = 13
  58.  
  59.     ma 
  60.  
  61.   The data came from the original posting; I modified it slightly to make it
  62.   easier to see if everything was working correctly.
  63.  
  64. What everyone is missing about procedures-that-do-the-job is the speed
  65. consideration.
  66.  
  67.   Well, o.k. - let's take a look.
  68.  
  69.     ma cat fi.icn
  70.  
  71.     procedure main()
  72.  
  73.       local numberchars, cnt, l
  74.  
  75.       numberchars := (&digits ++ 'e' ++ 'E' ++ '+' ++ '-' ++ '.')
  76.       cnt := 0
  77.  
  78.       while l := read() do
  79.     l ?
  80.       every tab(past("XMULT:"|"XZERO:"|"YMULT:"|"YZERO:", &subject)) do {
  81.         write(tab(many(numberchars)))
  82.         cnt +:= 1
  83.         }
  84.  
  85.       write("cnt = ", cnt)
  86.  
  87.       end # main
  88.  
  89.     procedure past(s1, s2, i1, i2)
  90.       suspend find(s1, s2, i1, i2) + *s1
  91.       end
  92.  
  93.     ma icont -u fi.icn
  94.     Translating:
  95.     fi.icn:
  96.       main
  97.       past
  98.     No errors
  99.     Linking:
  100.  
  101.     ma ./fi < dat
  102.     1.11E-4
  103.     1.12E-4
  104.     1.13E-4
  105.     1.14E-4
  106.     4.21E-8
  107.     4.22E-8
  108.     4.23E-8
  109.     1.31E-6
  110.     1.32E-6
  111.     1.33E-6
  112.     0.41E+0
  113.     0.42E+0
  114.     0.43E+0
  115.     cnt = 13
  116.  
  117.     ma i=0; while [ $i -lt 100 ]; do cat dat; i=`expr $i + 1`; done > dat.big
  118.  
  119.     ma wc -l dat dat.big
  120.        1 dat
  121.      100 dat.big
  122.      101 total
  123.  
  124.     ma time re < dat.big
  125.     cnt = 1300
  126.  
  127.     real    0m2.11s
  128.     user    0m1.92s
  129.     sys        0m0.03s
  130.  
  131.     ma time ./fi < dat.big
  132.     cnt = 1300
  133.  
  134.     real    0m0.28s
  135.     user    0m0.13s
  136.     sys        0m0.06s
  137.  
  138.     ma 
  139.  
  140.   Re and fi were modified to avoid printing matched values.  Regular
  141.   expressions are an order of magnitude slower than the past generator on a
  142.   sun ultra 2 with 168 mhz cpus and 128 meg of main store.  I don't know what
  143.   your situation is, but I'd be happy to pay the price in performance to get a
  144.   more understandable (to me) parser (I realize this wasn't the dichotomy set
  145.   up by the original poster).
  146.  
  147. Think about embedding either procedure in a deep inner loop of some kind.
  148.  
  149.   Yeah, so?  Either your parsing the same string over and over in a loop, in
  150.   which case procedures aren't your problem, or you're parsing a new string
  151.   every time, in which case what else are you going to do?
  152.  
  153.  
  154.